/**
 * 
 */
package com.xbang.attendance.web.action.system.sign2;

import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Map;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;

import com.demo2do.lighturl.annotation.Action;
import com.xbang.attendance.entity.Sign.detail;
import com.xbang.attendance.service.SystemService;
import com.xbang.core.page.Result;
import com.xbang.core.struts.support.SearchActionSupport;

/**
 * @author dev.zhang
 * 
 */
public class Search extends SearchActionSupport {

	private static final Log logger = LogFactory.getLog(Search.class);

	private static final long serialVersionUID = -1120551442020217513L;


	@Autowired
	private SystemService systemService;
	private List<detail> details = new ArrayList<detail>();
	

	public String execute() throws Exception {
		//details = systemService.getObjects(detail.class);
		return "search";
	}

	
	@Action("/system/sign2/search/do")
	public String doSearch() throws Exception {
		String hqlSentence = "FROM detail detail WHERE 1 = 1 ";
     	Map map =	searchComponent.getParameters();     	
     	String username =	(String) map.get("eqDetailUserName");  
     	Date starttime=	(Date) map.get("geqDetailDate");
     	if(starttime!=null){
     		String dateStr = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(starttime);
     		searchComponent.getParameters().remove("geqDetailDate");
     		searchComponent.getParameters().put("geqDetailDate", dateStr);
     	}
     	Date endtime =	(Date) map.get("leqDetailDate");
     	if(endtime!=null){
     		String dateStr = new SimpleDateFormat("yyyy-MM-dd hh:mm:ss").format(endtime);
     		searchComponent.getParameters().remove("leqDetailDate");
     		searchComponent.getParameters().put("leqDetailDate", dateStr);
     	}  
     	  
     	
     	
		if (searchComponent.getOrderParameters().isEmpty()){
			searchComponent.addSearchElement("orderBy.detail.date",  "ASC");			
		}
		Result result = systemService.searchByPage(hqlSentence, searchComponent, page);
		details = result.getItems();
	//	page = result.getPage();

		return "index";
	}

	@Override
	public void resetCustomerSearchCriteria() {
		// TODO Auto-generated method stub

	}

	public SystemService getSystemService() {
		return systemService;
	}

	public void setSystemService(SystemService systemService) {
		this.systemService = systemService;
	}

	public List<detail> getDetails() {
		return details;
	}

	public void setDetails(List<detail> details) {
		this.details = details;
	}



}
